package com.share.example.sbsjw.compent;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.share.common.utils.MockUtil;
import com.share.example.sbsjw.mapper.DictionaryMapper;
import com.share.example.sbsjw.mapper.StLogMapper;
import com.share.example.sbsjw.mapper.StOrderMapper;
import com.share.example.sbsjw.model.po.Dictionary;
import com.share.example.sbsjw.model.po.StLog;
import com.share.example.sbsjw.model.po.StOrder;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Data
@Slf4j
@Component
@EnableScheduling
public class GenData {

    @Autowired
    private StLogMapper accessLogMapper;

    @Autowired
    private StOrderMapper orderMapper;

    @Autowired
    private DictionaryMapper dictionaryMapper;

    @Scheduled(cron = "0/10 * * * * ?")
    public void gen() {
        StLog po = new StLog();
        po.setCreateTime(new Date());
        po.setCost(System.currentTimeMillis());
        po.setStartTime(new Date());
        po.setData(MockUtil.userName());
        po.setType("String");
        accessLogMapper.insert(po);
        List<StLog> logs = accessLogMapper.selectList(Wrappers.<StLog>query().ge("create_time", new Date()));
        log.info("日志list.size={}", logs.size());


        StOrder order = new StOrder();
        order.setUserId(MockUtil.faker.number().randomNumber());
        order.setData(MockUtil.mobilePhone());
        order.setType("手机号");
        order.setCreateTime(new Date());
        orderMapper.insert(order);
        List<StOrder> orders = orderMapper.selectList(Wrappers.<StOrder>query().ge("user_id", 1123L));/*强制要求类型一致,由于会分片所以有问题*/
        log.info("订单list.size={}", orders.size());


        List<Dictionary> dictionary = dictionaryMapper.listAll();
        log.info("字典list.size={}", dictionary.size());
    }
}
